package com.itheima.Game;

import java.util.*;

public class game
{
    private List<Card> cards=new ArrayList<>();
    //准备花色和点数
    int large=0;
    {
        String[] colors = {"♠", "♥", "♣", "♦"};
        String[] numbers = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        //组合数字和花色成为牌对像
        for (String number : numbers) {
            large++;
            for (String color : colors) {
                Card card=new Card(number,color,large);
                cards.add(card);
            }
        }
        Collections.addAll(cards,new Card("大王","",++large),new Card("小王","",++large));
    }

    public void start()
    {
        //打乱所有牌
        Collections.shuffle(cards);
        System.out.println( cards);
        //定义三个玩家
        Map<String,List<Card>> players=new HashMap<>();
        List< Card>player1=new ArrayList<>();
        players.put("玩家1",player1);
        List< Card>player2=new ArrayList<>();
        players.put("玩家2",player2);
        List< Card>player3=new ArrayList<>();
        players.put("玩家3",player3);
        //发牌
            for (int i = 0; i < cards.size()-3; i++) {
                Card card = cards.get(i);
                    if(i%3==0) {
                        player1.add(card);
                    }else if(i%3==1) {
                        player2.add(card);
                    }else{
                        player3.add(card);
                    }
            }
            //最后三张底牌
        List< Card>poker=cards.subList(cards.size()-3,cards.size());
            players.put("底牌",poker);
            //抢地主
        System.out.println("玩家1抢地主");
        player1.addAll(poker);
        //排序
        sortedCard(player1);
        sortedCard(player2);
        sortedCard(player3);
        //显示
        System.out.println("玩家1："+player1);
        System.out.println("玩家2："+player2);
        System.out.println("玩家3："+player3);
    }

    private void sortedCard(List<Card> player) {
        Collections.sort(player, (o1, o2) -> o2.getLarge()-o1.getLarge());
    }

}
